using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.UI.Base;
using Habanero.UI.Win;
using UseCaseManager.BO;

namespace UseCaseManager.UI
{
    /// <summary>
    /// A read-only grid control used for adding and editing Drops.
    /// </summary>
    public class DropsEditableGridControl : UserControlWin, IFormControl
    {
        private readonly IControlFactory _controlFactory;

        public DropsEditableGridControl(IControlFactory controlFactory)
        {
            _controlFactory = controlFactory;

            // Create the editable grid
            IEditableGridControl dropGridControl = _controlFactory.CreateEditableGridControl();
            
            // Used to specify a custom UI def
            dropGridControl.Initialise(ClassDef.Get<Drop>(), "default");

            // Load the collection of Drops.  You can set the criteria and order by values here.
            BusinessObjectCollection<Drop> sampleCollection = Broker.GetBusinessObjectCollection<Drop>("", "");
            dropGridControl.BusinessObjectCollection=sampleCollection;

            // Set this to true to enable the filters, then add your filters below (see commented out line)
            dropGridControl.FilterControl.Visible = false;
            //dropGridControl.FilterControl.AddStringFilterTextBox("", "");

            // Add the grid to the control so that it fills the control
            BorderLayoutManager layoutManager = _controlFactory.CreateBorderLayoutManager(this);
            layoutManager.AddControl(dropGridControl, BorderLayoutManager.Position.Centre);
        }

        /// <summary>
        /// Called whenever the control is placed on a form by the menu system.  Put any initialisation
        /// code in here that must be run whenever the form is displayed.
        /// </summary>
        public void SetForm(IFormHabanero form) { }
    }
}